home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / Triton / Source / classes / framebox.c < prev    next >
C/C++ Source or Header  |  1998-05-23  |  9KB  |  250 lines

  1. /*
  2.  *  OpenTriton -- A free release of the triton.library source code
  3.  *  Copyright (C) 1993-1998  Stefan Zeiger
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  */
  20.  
  21.  
  22. /****** triton.library/class_FrameBox ******
  23. *
  24. *   NAME    
  25. *    class_FrameBox -- A framing box
  26. *
  27. *   SUPERCLASS
  28. *    class_DisplayObject (no attributes inherited)
  29. *
  30. *   SYNOPSIS
  31. *    TROB_FrameBox
  32. *
  33. *   ATTRIBUTES
  34. *    <Default>        : ULONG boxtype (V2)
  35. *                         If no flag is set, unnamed boxes will
  36. *                         be grouping and named ones framing.
  37. *                       - TRFB_TEXT       : A text container
  38. *                       - TRFB_GROUPING   : A grouping box
  39. *                       - TRFB_FRAMING    : A framing box.
  40. *                       [create]
  41. *    TRAT_ID          : ULONG objectid (V2)
  42. *                       [create]
  43. *    TRAT_Backfill    : ULONG pattern
  44. *                       [create, set]
  45. *    TRAT_Text        : STRPTR label (V2)
  46. *                       [create]
  47. *    <other>          : <Child object>
  48. *                       [create]
  49. *
  50. ******/
  51.  
  52.  
  53. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  54. //////////////////////////////////////////////////////////////////////////////////////// Include our stuff //
  55. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  56.  
  57. #define TR_THIS_IS_TRITON
  58.  
  59. #include <clib/alib_protos.h>
  60. #include <libraries/triton.h>
  61. #include <clib/triton_protos.h>
  62. #include "/internal.h"
  63. #include "framebox.def"
  64.  
  65. #include <stdio.h>
  66. #include <ctype.h>
  67.  
  68.  
  69. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  70. ////////////////////////////////////////////////////////////////////////////////////////////// Object data //
  71. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  72.  
  73. #define OBJECT (&(object->DO.O))
  74. #define DISPLAYOBJECT (&(object->DO))
  75. #define FRAMEBOX object
  76.  
  77.  
  78. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  79. /////////////////////////////////////////////////////////////////////////////////////////// The dispatcher //
  80. /////////////////////////////////////////////////////////////////////////////////////////////////////////////
  81.  
  82. TR_DEFAULTMETHOD(FrameBox)
  83. {
  84.   struct TR_Project *project;
  85.   struct TROM_NewData newdata;
  86.   struct TROM_InstallData installdata;
  87.   BOOL found_one=FALSE;
  88.   ULONG left, top, width, height;
  89.   ULONG borderwidth,borderheight;
  90.   STRPTR newtext;
  91.   ULONG textwidth;
  92.   LONG uspos;
  93.  
  94.   switch(messageid)
  95.     {
  96.     case TROM_NEW:
  97.       NEWDATA->parseargs=FALSE;
  98.       if(!TRDP_DisplayObject_NEW(object,messageid,data,metaclass->trc_SuperClass)) return NULL;
  99.  
  100.       newtext=NULL;
  101.  
  102.       for(;;)
  103.     {
  104.       switch(NEWDATA->firstitem->ti_Tag)
  105.         {
  106.         case TRAT_ID:
  107.           DISPLAYOBJECT->ID=NEWDATA->firstitem->ti_Data;
  108.           break;
  109.         case TRAT_Backfill:
  110.           DISPLAYOBJECT->BackfillType=NEWDATA->firstitem->ti_Data;
  111.           break;
  112.         case TRAT_Text:
  113.           newtext=(STRPTR)(NEWDATA->firstitem->ti_Data);
  114.           break;
  115.         default:
  116.           if(found_one==TRUE) goto nomoretags;
  117.           else
  118.         {
  119.           newdata.project=NEWDATA->project;
  120.           newdata.grouptype=NULL;
  121.           newdata.firstitem=(((struct TROM_NewData *)(data))->firstitem)+1;
  122.           newdata.objecttype=NEWDATA->firstitem->ti_Tag;
  123.           newdata.itemdata=NEWDATA->firstitem->ti_Data;
  124.           newdata.backfilltype=DISPLAYOBJECT->BackfillType;
  125.           FRAMEBOX->ChildObject=
  126.             (struct TROD_DisplayObject *)TR_DoMethod(NULL,TROM_NEW,(APTR)&newdata);
  127.           NEWDATA->firstitem=newdata.firstitem-1;
  128.           found_one=TRUE;
  129.         }
  130.         }
  131.       NEWDATA->firstitem++;
  132.     }
  133.     nomoretags:
  134.  
  135.       if(!FRAMEBOX->ChildObject) return NULL;
  136.  
  137.       if(newtext)
  138.     {
  139.       FRAMEBOX->TextLength=TR_FirstOccurance(0,newtext)+1;
  140.       if(!(FRAMEBOX->Text=(STRPTR)AllocVec(FRAMEBOX->TextLength, MEMF_ANY))) return NULL;
  141.       CopyMem((APTR)newtext,(APTR)(FRAMEBOX->Text),FRAMEBOX->TextLength);
  142.       FRAMEBOX->BoxType=TRFT_ABSTRACT_FRAMEBOX;
  143.     }
  144.       else FRAMEBOX->BoxType=TRFT_ABSTRACT_GROUPBOX;
  145.  
  146.       if(FRAMEBOX->Flags&TRFB_GROUPING) FRAMEBOX->BoxType=TRFT_ABSTRACT_GROUPBOX;
  147.       if(FRAMEBOX->Flags&TRFB_FRAMING) FRAMEBOX->BoxType=TRFT_ABSTRACT_FRAMEBOX;
  148.  
  149.       borderwidth=TR_FrameBorderWidth(NEWDATA->project,FRAMEBOX->BoxType);
  150.       borderheight=TR_FrameBorderHeight(NEWDATA->project,FRAMEBOX->BoxType);
  151.  
  152.       DISPLAYOBJECT->XResize   = FRAMEBOX->ChildObject->XResize;
  153.       DISPLAYOBJECT->YResize   = FRAMEBOX->ChildObject->YResize;
  154.       DISPLAYOBJECT->MinWidth  = FRAMEBOX->ChildObject->MinWidth  + (2*borderwidth);
  155.       DISPLAYOBJECT->MinHeight = FRAMEBOX->ChildObject->MinHeight + (2*borderheight);
  156.  
  157.       if(FRAMEBOX->Text)
  158.     {
  159.       FRAMEBOX->PixelTextLength=TR_TextWidth(NEWDATA->project,(STRPTR)(FRAMEBOX->Text),TRTX_TITLE);
  160.       textwidth=FRAMEBOX->PixelTextLength+((NEWDATA->project->trp_PropFont->tf_YSize)*3);
  161.       DISPLAYOBJECT->MinWidth=max(DISPLAYOBJECT->MinWidth,textwidth);
  162.       DISPLAYOBJECT->MinHeight+=(NEWDATA->project->trp_TotalPropFontHeight-borderheight);
  163.     }
  164.  
  165.       return (ULONG)TR_AddObjectToIDList(NEWDATA->project, object);
  166.  
  167.  
  168.     case TROM_SETATTRIBUTE:
  169.       if((SETATDATA->attribute)!=TRAT_Backfill) return 0;
  170.       DISPLAYOBJECT->BackfillType=SETATDATA->value;
  171.       if(DISPLAYOBJECT->Installed) messageid=TROM_REFRESH;
  172.       else return 1;
  173.  
  174.  
  175.     case TROM_INSTALL:
  176.     case TROM_REFRESH:
  177.       TR_SUPERMETHOD;
  178.  
  179.       project = OBJECT->Project;
  180.       left    = DISPLAYOBJECT->Left;
  181.       top     = DISPLAYOBJECT->Top;
  182.       width   = DISPLAYOBJECT->Width;
  183.       height  = DISPLAYOBJECT->Height;
  184.  
  185.       borderwidth=TR_FrameBorderWidth(project,FRAMEBOX->BoxType);
  186.       borderheight=TR_FrameBorderHeight(project,FRAMEBOX->BoxType);
  187.  
  188.       if(FRAMEBOX->BoxType==TRFT_ABSTRACT_FRAMEBOX)
  189.     {
  190.       TR_InternalAreaFill(project,NULL,left+borderwidth,
  191.                   top+((project->trp_TotalPropFontHeight-borderheight)/2)+borderheight,
  192.                   left+width-1-borderwidth,top+height-1-borderheight,
  193.                   DISPLAYOBJECT->BackfillType);
  194.       TR_DrawFrame(project,NULL,
  195.                left,top+((project->trp_TotalPropFontHeight-borderheight)/2),
  196.                width,height-((project->trp_TotalPropFontHeight-borderheight)/2),
  197.                FRAMEBOX->BoxType,FALSE);
  198.       TR_InternalAreaFill(project,NULL,left+((width-FRAMEBOX->PixelTextLength)/2)
  199.                   -(project->trp_PropFont->tf_YSize)/2,top,
  200.                   left+((width-FRAMEBOX->PixelTextLength)/2)+FRAMEBOX->PixelTextLength
  201.                   +(project->trp_PropFont->tf_YSize)/2,
  202.                   top+project->trp_TotalPropFontHeight,
  203.                   DISPLAYOBJECT->BackfillType);
  204.       TR_PrintText(project,project->trp_Window->RPort,FRAMEBOX->Text,
  205.                left+((width-FRAMEBOX->PixelTextLength)/2),top,0,TRTX_TITLE);
  206.       top+=(project->trp_TotalPropFontHeight-borderheight);
  207.       height-=(project->trp_TotalPropFontHeight-borderheight);
  208.  
  209.       if((messageid==TROM_INSTALL)&&
  210.          (uspos=TR_FirstOccurance(project->trp_Underscore,FRAMEBOX->Text)+1))
  211.         DISPLAYOBJECT->Shortcut=tolower(FRAMEBOX->Text[uspos]);
  212.     }
  213.       else
  214.     {
  215.       TR_InternalAreaFill(project,NULL,
  216.                   left+borderwidth,top+borderheight,
  217.                   left+width-1-borderwidth,top+height-1-borderheight,
  218.                   DISPLAYOBJECT->BackfillType);
  219.       TR_DrawFrame(project,NULL,left,top,width,height,FRAMEBOX->BoxType,FALSE);
  220.     }
  221.  
  222.       installdata.left   = left+borderwidth;
  223.       installdata.top    = top+borderheight;
  224.       installdata.width  = width-(2*borderwidth);
  225.       installdata.height = height-(2*borderheight);
  226.  
  227.       return TR_DoMethod((struct TROD_Object *)(FRAMEBOX->ChildObject),messageid,(APTR)&installdata);
  228.  
  229.  
  230.     case TROM_CREATECLASS:
  231.     case TROM_DISPOSECLASS:
  232.     case TROM_KEYUP:
  233.     case TROM_KEYDOWN:
  234.     case TROM_KEYCANCELLED:
  235.     case TROM_DISABLED:
  236.     case TROM_ENABLED:
  237.       return NULL; /* Don't forward */
  238.  
  239.  
  240.     case TROM_DISPOSE:
  241.       if(FRAMEBOX->Text) FreeVec((APTR)(FRAMEBOX->Text));
  242.       return TR_DoMethod((struct TROD_Object *)(FRAMEBOX->ChildObject),messageid,data);
  243.  
  244.  
  245.     default:
  246.       TR_SUPERMETHOD;
  247.       return TR_DoMethod((struct TROD_Object *)(FRAMEBOX->ChildObject),messageid,data);
  248.     }
  249. }
  250.